<template>
  <div class="login-page">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span class="login-title">🔐学生密码登录</span>
      </div>
      <div class="login-form">
        <el-form :model="form" :rules="loginRules" ref="loginForm">
          <el-form-item prop="student_number">
            <el-input type="text" v-model="form.student_number" auto-complete="off" placeholder="请输入学号">
              <template slot="prepend"><i style="font-size:20px" class="el-icon-user"></i></template>
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
              <el-input type="text" v-model="form.password" auto-complete="off" placeholder="请输入密码">
                <template slot="prepend"><i style="font-size:20px" class="el-icon-key"></i></template>
              </el-input>
          </el-form-item>

          <el-form-item>
            <el-button style="width:340px;" type="primary" @click="LoginJudge" :loading="loading">登录</el-button>
          </el-form-item>
          <el-form-item>
            <el-link href="/LoginByEmailForStu" style="color: white">
              <el-button style="width:340px;" type="primary">
                验证码登录
              </el-button>
            </el-link>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>

import axios from "axios";
import Qs from 'qs'
export default {
  name: 'Login',
  mounted() {
    localStorage.removeItem('token');
  },

  data() {
    return {
      countDown: 0,
      loading: false,
      form: {
        student_number: '',
        password: ''
      },
      loginRules: {
        student_number: [
          {required: true, message: '请输入学号', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    LoginJudge() {
      axios({
        method: 'post',
        url: 'http://localhost:80/StuLoginJudge',
        params: {
          student_number: this.form.student_number,
          password: this.form.password
        },


      })
          .then(res => {
            console.log(res);
            console.log(res.status);
            var result=res.data
            if (result.code === 1) {
              this.$message.error(result.message);
            } else{
              localStorage.setItem('token', res.data.data) ;
              this.$message.success('登录成功');
              this.$router.push('/Stu_Info')
            }
          })
          .catch(err => {
            console.log(err);
          })
    }
  }
}
</script>

<style scoped>
.login-page{
  background-image: linear-gradient(180deg, #2af598 0%, #009efd 100%);
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-title{
  font-size: 20px;
}

.box-card {
  width: 375px;
}

</style>
